package com.bao.work.work02;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.FileReader;
import java.util.List;

/**
 * @author baoye
 * @date 2024-08-13/17:10
 */
public class Test02 {
    public static void main(String[] args)throws Exception {
        SAXReader saxReader=new SAXReader();
        FileReader fr=new FileReader("day15/src/com/bao/work/work01/bookstore.xml");
        Document document=saxReader.read(fr);
        Element bookstore = document.getRootElement();
        System.out.println(bookstore.getName());
        List<Element> books = bookstore.elements();
        for (Element book : books) {
            System.out.println("\t"+book.getName()+":"+book.attributeValue("category"));
            for (Element bm : book.elements()) {
                System.out.print("\t\t"+bm.getName()+":"+bm.getText());
                if(bm.getName().equals("title")){
                    System.out.print("\t"+bm.attributeValue("lang"));
                } System.out.println();
            }
        }

    }
}
